package com.killer.blog.service;

import com.killer.blog.pojo.Article;
import com.killer.blog.repository.ArticleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleService {

    @Autowired
    private ArticleRepository articleRepository;

    public Page<Article> listArticle(Integer page,Integer pageLength){
        //分页信息
        Pageable pageable = PageRequest.of(page==null||page.intValue()<=0?0:page-1, pageLength); //页码：前端从1开始，jpa从0开始，做个转换
        Page<Article> pages = articleRepository.findAll(pageable);
        return pages;
    }

}
